package io.renren.common.service.impl;

import io.renren.common.convert.RecVedioConvert;
import io.renren.common.entry.DTO.VedioDTO;
import io.renren.common.entry.SysUserEntity;
import io.renren.common.utils.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.config.Constant;
import io.renren.common.dao.RecVedioInfoDao;
import io.renren.common.entry.RecVedioInfoEntity;

import io.renren.common.service.RecVedioInfoService;
import io.renren.common.utils.PageUtils;

import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;


@Service("recVedioInfoService")
public class RecVedioInfoServiceImpl extends ServiceImpl<RecVedioInfoDao, RecVedioInfoEntity> implements RecVedioInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<RecVedioInfoEntity> page = this.page(
                new Query<RecVedioInfoEntity>().getPage(params),
                new QueryWrapper<RecVedioInfoEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void saveVedio(RecVedioInfoEntity recVedioInfo) {

        SysUserEntity user =    (SysUserEntity) SecurityUtils.getSubject().getPrincipal() ;

        recVedioInfo.setCtreaeid(user.getUserId());

        recVedioInfo.setDelFlag(Constant.DEL_STATUS);

        recVedioInfo.setCreatetime(new Date());

        this.save(recVedioInfo) ;

    }

    @Override
    public List<VedioDTO> queryHonePage() {

        List<RecVedioInfoEntity> list = list();

        List<VedioDTO> vedioDTOList =   RecVedioConvert.INSTANCE.toDtoList(list) ;

        return vedioDTOList;
    }

}
